package com.penghe.www.httplibrary

import com.yanzhenjie.nohttp.NoHttp
import com.yanzhenjie.nohttp.RequestMethod
import com.yanzhenjie.nohttp.rest.OnResponseListener
import com.yanzhenjie.nohttp.rest.RequestQueue
import com.yanzhenjie.nohttp.rest.Response

/**
 * Created by pengh on 2017/5/29.
 *
 *  NoHttp方式请求的实体类
 */

class NoHttpProcessor:IHttpProcessor{
    private var mQueue:RequestQueue = NoHttp.newRequestQueue()
    override fun get(url: String, params: Map<String, Any>, callBack: ICallBack) {
        val stringRequest = NoHttp.createStringRequest(url, RequestMethod.GET)
        mQueue.add(0,stringRequest,object :OnResponseListener<String>{
            override fun onFinish(what: Int) {
            }

            override fun onSucceed(what: Int, response: Response<String>) {
                callBack.onSucceeded(response.get())
            }

            override fun onStart(what: Int) {
            }

            override fun onFailed(what: Int, response: Response<String>) {
                callBack.onFailed(response.get())
            }

        })
    }

    override fun post(url: String, params: Map<String, Any>, callBack: ICallBack) {
    }

}